package com.leetcode.LC;

import java.util.ArrayList;
import java.util.List;

public class LC228 {
    public List<String> summaryRanges(int[] nums) {

        int start, end;

        ArrayList<String> list = new ArrayList<>();

        for (int i = 0; i < nums.length; i++) {
            start = nums[i];
            while (i + 1 < nums.length && nums[i + 1] == nums[i] + 1) {
                i = i + 1;
            }
            end = nums[i];
            if (start == end) {
                list.add(start + "");
            } else {
                list.add(start + "->" + end);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        for (String summaryRange : new LC228().summaryRanges(new int[]{0, 2, 3, 4, 6, 8, 9})) {
            System.out.print(summaryRange + ",");
        }
    }
}
